﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.IO;

namespace WpfHeroTutorial
{
    public class SongBrowser
    {
        private readonly ObservableCollection<MyDirectory> subDirectories = new ObservableCollection<MyDirectory>();

        public ObservableCollection<MyDirectory> SubDirectories { get { return subDirectories; }}

        private MyDirectory currentDirectory; 

        public MyDirectory CurrentDirectory
        {
            get { return currentDirectory; }
            set 
            {
                currentDirectory = value;
                if (currentDirectory == null)
                    return;

                subDirectories.Clear();

                if (Directory.GetDirectoryRoot(CurrentDirectory.FullPath) != CurrentDirectory.FullPath)
                    subDirectories.Add(new MyDirectory(Directory.GetParent(CurrentDirectory.FullPath).FullName, true));

                foreach (var dir in Directory.GetDirectories(CurrentDirectory.FullPath))
                    subDirectories.Add(new MyDirectory(dir, false));
            }
        }

        public SongBrowser()
        {
            CurrentDirectory = new MyDirectory(Directory.GetCurrentDirectory(), false);
        }

    }
}
